<template>
	<view class="content">
		<view style="position: relative;">
			<image class="bg" :src="$store.state.images.search_2" mode="widthFix"></image>
		</view>
		<navBar class="nav-bar" title="门店详情"></navBar>
		
		<view class="shop-card-1">
			<image class="icon"></image>
			<view class="title">
				<text>{{shop.ShopName}}</text>
				<view class="tip">
					<image class="tip-ic" src="../../static/ic_bao.png">
						
					</image>
					<text class="tip-text">星梦保</text>
				</view>
			</view>
			<view>
				<view class="tip like" @click="collect">
					<image class="tip-ic like" src="../../static/ic_like.png" mode="widthFix">
						
					</image>
					<text class="tip-text like">{{isCollect?"已收藏":"收藏"}}</text>
				</view>
			</view>
		</view>
		
		<view class="shop-card-2">
			<view class="row">
				<text>营业时间:</text>
				<text class="value">{{shop.businessHours}}</text>
			</view>
			<view class="row" @click="openLocation">
				<text>门店地址:</text>
				<text class="value">{{shop.CorpAddress}}</text>
				<image class="row-ic" src="../../static/ic_arrow_right.png" mode="widthFix"></image>
			</view>
			<view class="row" @click="callPhone">
				<text>门店电话:</text>
				<text class="value">{{shop.Mobile}}</text>
				<image class="row-ic" src="../../static/ic_arrow_right.png" mode="widthFix"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import navBar from '../../widgets/nav_bar.vue'
	import { mapState } from 'vuex';
	export default {
		components: {
			navBar,
		},
		data() {
			return {
				shop: {},
			}
		},
		methods: {
			openLocation() {
				const { Latitude, Longitude, ShopName, CorpAddress } = this.shop;
				uni.openLocation({
					latitude: Number(Latitude),
					longitude: Number(Longitude),
					scale: 18,
					name: ShopName,
					address: CorpAddress,
				})
			},
			callPhone() {
				const {Mobile} = this.shop;
				uni.makePhoneCall({
					phoneNumber:Mobile,
				})
			},
			collect() {
				let TypeCode = this.shop.ShopCode;
				
				if (this.isCollect) {
					this.$store.dispatch('delMyCollect', { CollectType: '门店', TypeCode})
				} else {
					this.$store.dispatch('addMyCollect', { CollectType: '门店', TypeCode})
				}
			}
		},
		onLoad({ index, type }) {
			if (type == "collect") {
				this.shop = this.$store.state.myShopCollect[index];
			} else {
				this.shop = this.$store.state.nearbyShop[index];
			}
		},
		computed: {
			...mapState(['myShopCollect']),
			isCollect() {
				// console.log('myShopCollect',this.myShopCollect)
				return this.myShopCollect.find(item => item.ShopCode == this.shop.ShopCode) != null
			},
		},
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		height: 100vh;
		box-sizing: border-box;
		overflow-y: scroll;
	}
	.nav-bar {
		position: absolute;
		top: 0;
		left: 0;
	}
	.bg {
		width: 100vw;
	}
	.shop-card-1 {
		font-family: "yshst" !important;
		z-index: 100;
		margin-left: 35rpx;
		margin-right: 35rpx;
		margin-top: -100rpx;
		background-color: white;
		border-radius: 15rpx;
		padding: 15rpx;
		display: flex;
		flex-direction: row;
	}
	.icon {
		width: 130rpx;
		height: 130rpx;
		min-width: 130rpx;
		border-radius: 15rpx;
		background-color: #e5f2f9;
	}
	.title {
		font-size: 35rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		flex: 1;
		padding: 0 25rpx;
	}
	.tip {
		display: flex;
		align-items: center;
		font-size: 28rpx;
	}
	.tip.like {
		margin-left: 15rpx;
		padding: 10rpx;
	}
	.tip-ic {
		width: 30rpx;
		height: 30rpx;
		margin-right: 4rpx;
	}
	.tip-text {
		color: #898989;
	}
	.tip-ic.like {
		width: 28rpx;
		height: 28rpx;
	}
	.tip-text.like {
		color: #898989;
	}
	
	.shop-card-2 {
		font-family: "yshst" !important;
		z-index: 100;
		margin-left: 35rpx;
		margin-right: 35rpx;
		margin-top: 15rpx;
		background-color: white;
		border-radius: 15rpx;
		padding: 25rpx;
		display: flex;
		flex-direction: column;
	}
	.shop-card-2 .row {
		display: flex;
		flex-direction: row;
		align-items: center;
		height: 65rpx;
	}
	.shop-card-2 .value {
		color: #50c0f9;
	    text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		flex: 1;
		margin-right: 15rpx;
		margin-left: 15rpx;
	}
	.shop-card-2 .row-ic {
		width: 15rpx;
	}
</style>
